<?php
/**
 * Created by PhpStorm.
 * User: xpz
 * Date: 2023/7/26
 * Time: 16:16
 */
namespace app\api\command\create;
use think\console\Command;
use think\console\Input;
use think\console\input\Option;
use think\console\Output;
use think\Exception;
use think\config;
use think\Db;
use app\api\command\spider\SpiderBase;
class Article extends SpiderBase
{
    protected function configure()
    {
        $this->setName('article')              		//定义命令的名字
        ->setDescription('article')      //定义命令的描述
        ->addArgument('method')                   //参数1
        ->addArgument('id');                    //文章id
    }

    //php think article updatestatus(publish)
    protected function execute(Input $input, Output $output)
    {

        ini_set('max_execution_time', 600);//秒为单位，自己根据需要定义

        $method = $input->getArgument('method');
        if($method == 'updatestatus'){
            $this->updatestatus();
        }
    }

    private function updatestatus(){
        $this->ticheck();
        $randTime = rand(0,2400);
        echo "需要延时：".$randTime."\r\n";
        sleep($randTime);
        $articleModel = model('app\common\model\Article');
        $articleData = $articleModel->where(['status'=>2])->order("id asc")->find();
        if(!empty($articleData)){
            $articleModel->where(['id'=>$articleData['id']])->update(['status'=>1,'updatetime'=>date('Y-m-d H:i:s')]);
            echo $articleModel->getLastSql()."\r\n";
        } else {
            echo "没有更新数据\r\n";
        }
    }





    protected function ticheck(){
        $nowH = (int)date("H",time());
        if($nowH < 8 || $nowH > 18){
            echo "不在提交时间内！";exit;
        }
    }








}